<?
	require("connect.inc.php");
    ($db = mysql_connect("$serveur", "$utilisateur", "$motdepasse")) or die("<CENTER><A style='color:white;background-color:red'> D�ol� probl�e de serveur</a><br><br>Impossible de se connecter au serveur</center><br></td></tr></table></body></html>");
    mysql_select_db("$database",$db) or die("<CENTER><A style='color:white;background-color:red'> D�ol� probl�e de serveur</a><br><br>Impossible de se connecter �la base de donn�s</center><br></td></tr></table></body></html>");
    
	
	//insert();
	redim();
	
	function redim(){
		$dirname = $_POST['dirname'];
		$num_album_tab = explode("/",$dirname);
	
		$num_album = $num_album_tab[((sizeof($num_album_tab))-1)];
		if ($handle = opendir($dirname)) {
		   while ($file = readdir($handle)) {		   
		       if ($file != "." && $file != "..") {
			       echo $file;			       
		           echo '<BR/>';
					if (!strstr($file,"mini")){	           	   
			           redimensionne($dirname."/".$file);
			       	}	
	       	}
	   	}
	   closedir($handle);
		}	
	}
    
	function insert(){		
		$dirname = $_POST['dirname'];
		$num_album_tab = explode("/",$dirname);
	
		$num_album = $num_album_tab[((sizeof($num_album_tab))-1)];
		if ($handle = opendir($dirname)) {
		   while ($file = readdir($handle)) {		   
		       if ($file != "." && $file != "..") {
			       echo $file;
			       
		           echo '<BR/>';
					if (strstr($file,"Photo")){
			       $tmp_time = time();
			       echo $tmp_ime;
			       $i = $tmp_time;
	   			   $time = $tmp_time + 1;
	   			   while ($i < $time)   {			
		   			    If (time() != $i) { $i++; }	  	   			    
			   			    echo " ";
		           		
	           	   }        
	           	   $ladate = date("Y-m-d h:i:s");
			       //$sql = "UPDATE `gimagelist` set date_verif = '".$ladate."' WHERE url = '".$file."'";
			       $sql = "INSERT INTO `gimagelist` (id,date_verif,label,url,album,hits) VALUES ('','".$ladate."','','".$file."',".$num_album.",0)";
			       mysql_query($sql);
			       echo '<BR/>';
			       echo $sql;
		           echo '<BR/>';
	// 	          echo $file." + ".$dirname;
	// 	           echo '<BR/>';
		           
		       	}	
	       	}
	   	}
	   closedir($handle);
		}	
	}
	
	

	
	function redimensionne($url_src) //voici la fonction qui redimensionne les images
{
	$url_dest = $url_src;
	$size = getimagesize($url_src);
    $rapport = 1;
    echo $url_src;
	echo '<BR/>';
    echo $size[0]." et ".$size[1];
    echo '<br/>';
    if ($size[0] > $size[1]){
	    if ($size[0] > 800){
	    	$rapport = (800 / $size[0]);
	    }
    }else{
	    if ($size[1] > 600){
	    	$rapport = (600 / $size[1]);
    	}
	}
    
    $dest_width = ($size[0] * $rapport);
    $dest_eight =  ($size[1] * $rapport);
        
    $src_img = imagecreatefromjpeg($url_src);
    $dst_img = imagecreatetruecolor($dest_width,$dest_eight);
    
    imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_eight, $size[0], $size[1]); // la fonction qui redimensionne les photos
    imagejpeg($dst_img, $url_dest, 60);
    imagedestroy($src_img);
    imagedestroy($dst_img); 
}
	
?>